package com.wenfs.demo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wenfs
 */
public class DateUtil {

  /**
   * 将时间转换为时间戳
   *
   * @param s
   * @return
   * @throws ParseException
   */
  public static String dateToStamp(String s) {
    String res;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = null;
    try {
      date = simpleDateFormat.parse(s);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    long ts = date.getTime();
    res = String.valueOf(ts);
    return res;
  }


  /**
   * 将时间戳转换为时间
   *
   * @param s
   * @return
   */
  public static String stampToDate(String s) {
    String res;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    long lt = new Long(s);
    Date date = new Date(lt);
    res = simpleDateFormat.format(date);
    return res;
  }



}
